package com.jk.hly.service.impl;

import com.jk.hly.bean.LoginLog;
import com.jk.hly.bean.RegisterLog;
import com.jk.hly.service.HlyLogService;
import com.jk.hly.util.ReceivePage;
import com.jk.hly.util.SendPage;
import org.springframework.data.mongodb.core.MongoTemplate;

import javax.annotation.Resource;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HlyLogServiceImpl  implements HlyLogService {

    @Resource
    private MongoTemplate mongoTemplate;

    @Override
    public SendPage queryLogList(ReceivePage page) {
        Query query = new Query();
        int total=(int) mongoTemplate.count(query, LoginLog.class);
        query.skip((page.getPage()-1)*page.getRows());
        query.limit(page.getRows());
        List<LoginLog> rows=mongoTemplate.find(query,LoginLog.class);
        SendPage sp=new SendPage(total,rows);
        return sp;
    }

    @Override
    public SendPage queryEmailList(ReceivePage page) {
        Query query = new Query();
        int total=(int) mongoTemplate.count(query, RegisterLog.class);
        query.skip((page.getPage()-1)*page.getRows());
        query.limit(page.getRows());
        List<RegisterLog> rows=mongoTemplate.find(query,RegisterLog.class);
        SendPage sp=new SendPage(total,rows);
        return sp;
    }
}
